package com.example.apicommon;

/**
 java.util.function.* 里面有
 Consumer  Function  Predicate
 **/
import java.util.function.*;
public class JavaFunInter {
    /*
        // BiConsumer 2入参, 不返回
        BiConsumer<String, Integer> b1 = (name, age) -> System.out.println(name + age);
        // BiFunction<P1, P2, RE> 2入参, 返回 RE
        BiFunction<String, Integer, String> b2 = (name, age) -> (name + age);

        // BiPredicate  2入参, 返回 boolean
        BiPredicate<String, Integer> b3 = (name, age) -> !name.isEmpty() && age > 18;
        // BinaryOperator<T> 代表了一个作用于于两个同类型操作符的操作，并且返回了操作符同类型的结果
        BinaryOperator<String> b4 = (s1, s2) -> s1 + s2;


        // Consumer<P> 1入参, 不返回  accept
        Consumer<String> c1 = System.out::println;

        // Function<P,R> 1入参, 返回  apply
        Function<Integer, Boolean> f1 = x -> x > 18;

        // Predicate<T> 1入参, 返回 boolean
        Predicate<String> p1 = s -> s.isEmpty();

     */
    public static void main(String[] args) {
    }

    // Predicate.test
    public static final void predicateTest() {
        // Predicate<T> 1入参, 返回 boolean
        // and or negate无参取反 test 四大方法
        Predicate<String> p1 = s -> !s.isEmpty();
        Predicate<String> p2 = s -> s.charAt(0) == 'a';
        Predicate<String> p3 = s -> s.charAt(s.length() - 1) == 'z';
        Predicate<String> p4 = p1.and(p2).and(p3);
        // predicateInstance.test(Param) -> boolean
        System.out.println(p4.test(""));
        System.out.println(p4.test("abcdz"));

        Predicate<String> p5 = s -> s.charAt(0) == 'A';
        System.out.println(p4.or(p5).test("A"));

        Predicate<String> p6 = s -> s.charAt(0) != 'A';
        Predicate<String> p7 = p6.negate();
        System.out.println(p6.test("A"));
        System.out.println(p7.test("A"));
    }
}
